﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;

namespace WXYW
{
    public partial class ManageRole : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindRoleGridView();
            }
        }

        private void BindRoleGridView()
        {
            RoleService service = new RoleService();
            RoleGridView.DataSource = service.GetRoleList();
            RoleGridView.DataBind();
        }

        protected void RoleGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FFFF99'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                ((Label)e.Row.FindControl("IDLbl")).Text = (e.Row.RowIndex + 1).ToString();
            }
        }

        protected void RoleGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Manage"))
            {
                Response.Redirect(string.Format("ManageRolePermission.aspx?{0}={1}", Constants.QUERYSTR_ROLE_ID, e.CommandArgument));
            }
            else if (e.CommandName.Equals("EditRole"))
            {
                Response.Redirect(string.Format("EditRole.aspx?{0}={1}", Constants.QUERYSTR_ROLE_ID, e.CommandArgument));
            }
        }
    }
}
